//
//  TTViewController.m
//  WxIOSReaderForiPhone
//
//  Created by lxxccc on 17-11-14.
//  Copyright (c) 2017年 anzeinfo. All rights reserved.
//

#import <QuartzCore/QuartzCore.h>
#import "TTViewController.h"
#import "UINavigationController+FDFullscreenPopGesture.h"

@interface TTViewController ()
@end

@implementation TTViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //导航按扭字体颜色设置
    self.navigationController.navigationBar.tintColor = [UIColor redColor];
    //设置导航条的色调 理解为"混合色"
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    //导航栏默认是半透明状态
    self.navigationController.navigationBar.backgroundColor = [UIColor blueColor];
    //导航按扭文本设置
    self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];    
    //不显示状态栏
    [self.navigationController setToolbarHidden:YES];
    //全屏右滑关闭
    self.fd_interactivePopDisabled = NO;
    //隐藏底部状态栏
    self.navigationController.toolbarHidden = YES;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //[self.navigationController setNavigationBarHidden:NO animated:YES];
    [[UIApplication sharedApplication]setStatusBarHidden:YES];
    //TODO 导航条内容设置
    /*UIImage *backImage = nil;//LOAD_IMAGE(@"nav_back");
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:backImage forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
    backBtn.frame = CGRectMake(0, 0, backImage.size.width, backImage.size.height);*/
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}
/*-(BOOL)prefersStatusBarHidden
{
    //返回YES表示隐藏状态栏，返回NO表示显示
    return YES;
}*/

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)backBtnPressed:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -自定义事件
- (void) showMessageBox:(NSString*)_message  autoHide:(Boolean)isAutoHide{
    [self showMessageBox:_message mode:MBProgressHUDModeText offset:CGPointMake(0, 0)];
    if(isAutoHide){
        [self hideMessageBox];
    }
}

- (void) showMessageBox:(NSString*)_message mode:(MBProgressHUDMode)_mode autoHide:(Boolean)isAutoHide{
    [self showMessageBox:_message mode:_mode offset:CGPointMake(0, 0)];
}

- (void) showMessageBox:(NSString*)_message mode:(MBProgressHUDMode)_mode offset:(CGPoint)offset{
    @autoreleasepool {
        if(nil != self.hud){
            [self.hud hideAnimated:YES];
            self.hud = nil;
        }
        self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        //self.hud.backgroundColor = [UIColor blackColor];
        //self.hud.bezelView.color = [[UIColor blueColor] colorWithAlphaComponent:0.5];
        self.hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        self.hud.bezelView.color = [UIColor colorWithWhite:0.f alpha:0.7f];
        self.hud.offset = offset;
        self.hud.mode = _mode;
        self.hud.detailsLabel.text = _message;
        [self.view bringSubviewToFront:self.hud];
        [self.hud showAnimated:YES];
    }

}

- (void) showMessageBoxOnWindow:(NSString*)_message mode:(MBProgressHUDMode)_mode
{
    @autoreleasepool {
        if(nil != self.hud){
            [self.hud hideAnimated:YES];
            self.hud = nil;
        }
        self.hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
        self.hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        self.hud.bezelView.color = [UIColor colorWithWhite:0.f alpha:0.7f];
        self.hud.offset = CGPointMake(0, 0);
        self.hud.mode = _mode;
        self.hud.detailsLabel.text = _message;
        self.hud.detailsLabel.textColor = [UIColor whiteColor];
        [self.view bringSubviewToFront:self.hud];
        [self.hud showAnimated:YES];
        [self hideMessageBox];
    }
}

- (void) hideMessageBox{
    if(nil != self.hud){
        [self.hud hideAnimated:YES afterDelay:2];
        self.hud = nil;
    }
}

- (UIImage *)imageWithColor:(UIColor *)color {
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


-(UIImage*)imageWithColor:(UIColor*)color size:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    
    CGRect rect=CGRectMake(0, 0, size.width, size.height);
    UIBezierPath*bezierPath = [UIBezierPath bezierPathWithRect:rect];
    //[UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:size.width/2.0];
    
    CGContextAddPath(context, bezierPath.CGPath);
    CGContextFillPath(context);
    CGContextSetFillColorWithColor(context, color.CGColor);
    UIImage*theImage=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}
@end
